import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/29 20:43
 * @description 方法一代码优化
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public int lengthOfLongestSubstring(String s) {
        char[] S = s.toCharArray();
        int[] cnt = new int[128];
        int n = s.length(), ans = 0;
        for (int i = 0, l = 0; i < n; i++) {
            cnt[S[i]]++;
            while (cnt[S[i]] > 1) {
                cnt[s.charAt(l)]--;
                l++;
            }
            ans = Math.max(ans, i - l + 1);
        }
        return ans;
    }
}
